package com.modificial.springboot.dao;

import com.modificial.springboot.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author modificial
 * @data 2018/12/3
 * @since 8:56
 */
@Repository
public class UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    /**
     * 查询所有用户
     *
     * @return
     */
    public List<User> listUsers() {
        String sql = "select * from  t_user";

        return jdbcTemplate.query(sql, (resultSet, i) -> {
            User user = new User();
            user.setAddress(resultSet.getString("address"));
            user.setAge(resultSet.getInt("age"));
            user.setBirthday(resultSet.getDate("birthday"));
            user.setSalary(resultSet.getBigDecimal("salary"));
            user.setName(resultSet.getString("name"));
            return user;
        });
    }
}
